﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CsharpWpfManual
{
    /// <summary>
    /// Log4net.xaml 的交互逻辑
    /// </summary>
    public partial class Log4net : Window
    {
        public Log4net()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            LogHelper.WriteLog("this is my first time use log4net");
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                int i = int.Parse("2a2");
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("an exception occured",ex);
                throw;
            }
            


        }
    }

    public class LogHelper
    {
        public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
        public static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");
        public static void WriteLog(string info)
        {
            if (loginfo.IsInfoEnabled)
            {
                loginfo.Info(info);
            }
        }

        public static void WriteLog(string info, Exception ex)
        {
            if (logerror.IsErrorEnabled)
            {
                logerror.Error(info, ex);
            }
        }
    }
}
